<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>媒体监测搜索</title>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/ssi_common.js"></script>
<script type="text/javascript" src="../../js/chosen.jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.placeholder.js"></script>
<script type="text/javascript" src="../../js/icheck.min.js"></script>
<script type="text/javascript" src="../../js/jquery.ui.core.js"></script>
<script type="text/javascript" src="../../js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="../../js/jquery.ui.widget.js"></script>
<script type="text/javascript"
	src="../../js/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="../../js/select2.min.js"></script>
<script type="text/javascript" src="../../js/select2_locale_zh-CN.js"></script>

<link href="../../style/select2/select2.css" type="text/css"
	rel="stylesheet" />
<link href="../../style/date_picker/jquery-ui.min.css" type="text/css"
	rel="stylesheet" />
<link href="../../style/global.css" type="text/css" rel="stylesheet" />
<link href="../../style/monitor.css" type="text/css" rel="stylesheet" />
<link href="../../style/icheck/green.css" type="text/css"
	rel="stylesheet" />
<link href="../../style/chosen/chosen.min.css" type="text/css"
	rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function(){
	
	$(".area_select").chosen({disable_search:true});
	$(".industry_select").chosen({disable_search:true,width: "160px"});
	$('.select_media_type').iCheck({
	      checkboxClass: 'icheckbox_minimal-green',
	      radioClass: 'iradio_minimal-green',
	      increaseArea: '20%' // optional
	    });
	$('.brand').placeholder();
    
	$( "#from" ).datepicker({
		changeMonth: true,
		numberOfMonths: 2,
		dateFormat:"yy-mm-dd",
		maxDate:"+0 d",
		onClose: function( selectedDate ) {
			$( "#to" ).datepicker( "option", "minDate", selectedDate );
		}
	});
	$( "#to" ).datepicker({
		changeMonth: true,
		numberOfMonths: 2,
		dateFormat:"yy-mm-dd",
		maxDate:"+0 d",
		onClose: function( selectedDate ) {
			$( "#from" ).datepicker( "option", "maxDate", selectedDate );
		}
	});

	$('.select_media_type').on('ifChecked', function(event){
		$(this).siblings().removeClass('on');
		$(this).addClass("on");
		$("#media_type").val($(this).val());
		if ($(this).val()=="highway") {
			$("#city").html("<option value=''>请选择</option>");
			$("#area").html("<option value=''>请选择</option>");
			$("#province").trigger("chosen:close");
			$("#city").trigger("chosen:updated");
			$("#area").trigger('chosen:updated');
			$("#area_zone").hide();
			$("#city").attr("name","highway");
			
			$("#city_zone").find(".chosen-container").css("width","220px");
			province_change();
		}else if($(this).val()=="airport") {
			$("#city").html("<option value=''>请选择</option>");
			$("#area").html("<option value=''>请选择</option>");
			$("#city").trigger("chosen:updated");
			$("#area").trigger('chosen:updated');
			$("#area_zone").hide();

			$("#city").attr("name","airport");
			$("#city_zone").find(".chosen-container").css("width","220px");
			province_change();
		}else{
			$("#city").html("<option value=''>请选择</option>");
			$("#area").html("<option value=''>请选择</option>");
			$("#city").trigger("chosen:updated");
			$("#area").trigger('chosen:updated');
			$("#area_zone").show();

			$("#city").attr("name","city");
			
			$("#city_zone").find(".chosen-container").css("width","130px");
			province_change();
		}
	});

	$("#brand_search").click(function(){
		$(this).addClass("on");
		$("#industry_search").removeClass("on");
		$(".brand_search").show();
		$(".industry_search").hide();
		$(".industry_select").val("");
		$(".industry_select").trigger('chosen:updated');
		$("#search_type_name").val("brand_search");
	});
	$("#industry_search").click(function(){
		$(this).addClass("on");
		$("#brand_search").removeClass("on");
		$(".brand_search").hide();
		$(".industry_search").show();
		$(".brand").val("");
		$("#industry_select").trigger('chosen:updated');
		$("#search_type_name").val("industry_search");
	});

	$(".brand").blur(function(){
		$("#search_auto").fadeOut(200);
	});
	$(".brand").keyup(function(){
		$("#search_name_type").val("");
		$("#brand_id").val("");
		if($(".brand").val().replace(/(^\s*)|(\s*$)/g, "").length!=0){
		 $.get(
			      "./search_brand",
			      {
			    	  keyword:$(".brand").val()
			      },
			      function (data) //回传函数
			      {
			        var myjson='';
			        eval('myjson=' + data + ';');
			        if(myjson["result"]!=""){
			        	$("#search_auto").show();
			        	$(".search_auto").html("");
			        	 for ( var i= 0; i < myjson["result"].length; i++) {
				        	 //判断是否是品牌还是产品名称
				        	 if (myjson['result'][i]['product_name']==undefined) {
								$(".search_auto").append("<li ><a href='javascript:void(0)' class='lianxiang' data_type='seasch_brand'  data='"+myjson['result'][i]['brand_name']+"'  id='"+myjson['result'][i]['id']+"' > <span>"+myjson['result'][i]['brand_name']+"</span> </a></li>");
							}else{
				        		$(".search_auto").append("<li ><a href='javascript:void(0)' class='lianxiang' data_type='seasch_product' data='"+myjson['result'][i]['product_name']+"'  id='"+myjson['result'][i]['id']+"'>"+myjson['result'][i]['product_name']+ " 在 <span>"+myjson['result'][i]['brand_name']+"</span> 中搜索"+"</a></li>");
							}
			        		
						}
			        	 $(".search_auto").append("<li id='li_close'><a href='javascript:void(0)' class='close_search'>关闭</a></li>");
			        	
				        }else{
							$("#search_auto").fadeOut(200);
						}
			      });
			}else{
				$("#search_auto").fadeOut(200);
			}
		
	  });
	$('#search_auto').delegate(".lianxiang", "mouseover",function() {
		$(this).addClass("hover"); 
	});
	$('#search_auto').delegate(".lianxiang", "mouseout",function () {
		$(this).removeClass("hover");
	});
	$('#search_auto').delegate(".close_search","click",function () {
		$("#search_auto").fadeOut(200);
	});
	$('#search_auto').delegate(".lianxiang","click",function(){
		
		$(".brand").val($(this).attr("data"));
		$("#search_name_type").val($(this).attr("data_type"));
		$("#brand_id").val($(this).attr("id"));
		
		$("#search_auto").fadeOut(200);
	});
	$(".monitor_title_list").click(function(){
		if($(this).next().is(":visible")){
			$(this).find(".list_sd").html("▼");
			$(this).next().hide();
		}else{
			$(this).find(".list_sd").html("▲");
			$(this).next().show();
		}
	});
	$("#show_thumb").click(function(){
			<?php $search_data1 =$search_data; ?>
		if($(this).attr("checked")){
			window.location.href="<?php $search_data1['show_type']="monitor_search_list";echo "?".http_build_query($search_data1)?>";
		}else{
			window.location.href="<?php $search_data1['show_type']="monitor_search_grid";echo "?".http_build_query($search_data1)?>";
		}
		
	});
	$("#remove_duplicate").click(function(){
		<?php $search_data1 =$search_data; ?>
	if($(this).attr("checked")){
		window.location.href="<?php $search_data1['remove_duplicate']="0";echo "?".http_build_query($search_data1)?>";
	}else{
		window.location.href="<?php $search_data1['remove_duplicate']="1";echo "?".http_build_query($search_data1)?>";
	}
	
});
});

function province_change(){
	var province = $("#province").val();
	if (province=="") {
		return ;	
	}

	if($("#media_type").val()=="common"||$("#media_type").val()=="led"){
		$.getJSON("<?php echo base_url()."index.php/region/get_regions"?>", { region_id: province }, function(json){
			$("#city").html("<option value=''>请选择</option>");
			$("#area").html("<option value=''>请选择</option>");
			if (json.length == 0) {
				$("#city").trigger('chosen:updated');
				$("#area").trigger('chosen:updated');
				return;
			}
			for(var i = 0, len = json.length; i<len; ++i){
				var region = json[i];
				$("#city").append("<option value=" + region.region_id + ">" + region.region_name + "</option>");
			}
			$("#city").trigger('chosen:updated');
			$("#area").trigger('chosen:updated');
		});
	}else if($("#media_type").val()=="highway"){
		$.getJSON("<?php echo base_url()."index.php/region/get_highways"?>", { region_id: province }, function(json){
			$("#city").html("<option value=''>请选择</option>");
			if (json.length == 0) {
				$("#city").trigger('chosen:updated');
				return;
			}
			
			for(var i = 0, len = json.length; i<len; ++i){
				var highway = json[i];
				$("#city").append("<option value=" + highway.highway_id + ">" + highway.highway_name + "</option>");
			}
			$("#city").trigger('chosen:updated');
		});
		
	}else if ($("#media_type").val()=="airport") {
		$.getJSON("<?php echo base_url()."index.php/region/get_airports"?>", { region_id: province }, function(json){
			$("#city").html("<option value=''>请选择</option>");
			if (json.length == 0) {
				$("#city").trigger('chosen:updated');
				return;
			}
			for(var i = 0, len = json.length; i<len; ++i){
				var airport = json[i];
				$("#city").append("<option value=" + airport.airport_id + ">" + airport.airport_name + "</option>");
			}
			$("#city").trigger('chosen:updated');
		});
		
	}
}
function city_change(){
	var city = $("#city").val();
	$.getJSON("<?php echo base_url()."index.php/region/get_regions"?>", { region_id: city }, function(json){
		if (json.length == 0) {
			return;
		}
		$("#area").html("<option value=''>请选择</option>");
		for(var i = 0, len = json.length; i<len; ++i){
			var region = json[i];
			$("#area").append("<option value=" + region.region_id + ">" + region.region_name + "</option>");
		}
		$("#area").trigger('chosen:updated');
	});
}
function industry_change(){
	var industry_id = $("#industry").val();
	$.getJSON("<?php echo base_url()."index.php/monitor/search_industry_category"?>", { industry_id: industry_id }, function(json){
		if (json.length == 0) {
			return;
		}
		$("#industry_category").html("<option value=''>请选择</option>");
		for(var i = 0, len = json.length; i<len; ++i){
			var industry = json[i];
			$("#industry_category").append("<option value=" + industry.industry_id + ">" + industry.industry_name + "</option>");
		}
		$("#industry_category").trigger('chosen:updated');
	});
}
function monitorFormatResult(monitor) {
    var itemFmt =monitor.brand_name+monitor.product_name; 
    return itemFmt;  
}

function monitorFormatSelection(monitor) {
    return monitor.brand_name+monitor.product_name;
}
</script>

</head>
<body>